package com.example.myapplication6;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.Toast;

public class MainActivity2 extends AppCompatActivity {
    private int score=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        Intent intent=getIntent();
        String user=intent.getStringExtra("user");
        Toast.makeText(this, user, Toast.LENGTH_LONG).show();
        FragmentManager fragmentManager=getSupportFragmentManager();
        FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.frame,new indexFragment());
        fragmentTransaction.commit();
    }

    public void section(View view) {
        FragmentManager fragmentManager=getSupportFragmentManager();
        FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.frame,new sectionFragment());
        fragmentTransaction.commit();
    }

    public void problem(View view) {
        FragmentManager fragmentManager=getSupportFragmentManager();
        FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.frame,new poneFragment());
        fragmentTransaction.commit();
    }

    public void gotwo(View view) {
        switch (view.getId()) {
            case(R.id.back):
            case(R.id.back1):
            case(R.id.back2):
                FragmentManager fragmentManager1 = getSupportFragmentManager();
                FragmentTransaction fragmentTransaction1 = fragmentManager1.beginTransaction();
                fragmentTransaction1.replace(R.id.frame, new sectionFragment());
                fragmentTransaction1.commit();
                break;
            default:
            FragmentManager fragmentManager = getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.frame, new ptwoFragment());
            fragmentTransaction.commit();
        }
    }

    public void goone(View view) {
        FragmentManager fragmentManager=getSupportFragmentManager();
        FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.frame,new poneFragment());
        fragmentTransaction.commit();
    }

    public void gothree(View view) {
        FragmentManager fragmentManager=getSupportFragmentManager();
        FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.frame,new pthreeFragment());
        fragmentTransaction.commit();
    }

    public void setScore(View view) {
        CheckBox checkBox1=findViewById(R.id.checkone);
        CheckBox checkBox2=findViewById(R.id.checktwo);
        CheckBox checkBox3=findViewById(R.id.checkthree);
        switch (view.getId()){
            case R.id.one:
                if(checkBox1.isChecked()) {
                    score+=1;
                    Toast.makeText(this, "恭喜您回答正确", Toast.LENGTH_SHORT).show();
                }
                else
                    Toast.makeText(this, "回答错误，正确答案为A", Toast.LENGTH_SHORT).show();
                break;
            case R.id.two:
                if(checkBox2.isChecked()) {
                    score+=1;
                    Toast.makeText(this, "恭喜您回答正确", Toast.LENGTH_SHORT).show();
                }
                else
                    Toast.makeText(this, "回答错误，正确答案为B", Toast.LENGTH_SHORT).show();
                break;
            case R.id.three:
                if(checkBox3.isChecked()) {
                    score+=1;
                    Toast.makeText(this, "恭喜您回答正确", Toast.LENGTH_SHORT).show();
                }
                else
                    Toast.makeText(this, "回答错误，正确答案为C", Toast.LENGTH_SHORT).show();
                Toast.makeText(this, "你的最终成绩为"+score, Toast.LENGTH_SHORT).show();
                break;
        }
    }
    public void changeback(View view) {
        LinearLayout layout=findViewById(R.id.index);
        layout.setBackgroundColor(Color.rgb(100,20,20));
    }
}